package edu.ubb.scrumster.model.repository;

import java.util.ArrayList;
import java.util.List;

import edu.ubb.scrumster.model.model.AbstractModel;
import edu.ubb.scrumster.model.model.Scrum;
import edu.ubb.scrumster.model.model.Sprint;
import edu.ubb.scrumster.model.model.User;

public class SprintRepository {

	public SprintRepository() {
	}

	public ArrayList<Sprint> getAllSprint() {
		ArrayList<Sprint> list = new ArrayList<Sprint>();
		for (AbstractModel d : DatabaseAccess.getInstance().getAll(DatabaseAccess.SPRINT)){
			list.add(getSprintById(((Sprint) d).getId()));
		}
		return list;
	}

	public void addSprint(Sprint g) {
		DatabaseAccess.getInstance().addData(g);
	}

	public void updateSprint(Sprint data) {
		DatabaseAccess.getInstance().updateData(data);
	}

	public void deleteSprint(Sprint data) {
		DatabaseAccess.getInstance().deleteData(data);
	}

	public Sprint getSprintById(int id) {
		Sprint s=(Sprint)DatabaseAccess.getInstance().getDataById(id, DatabaseAccess.SPRINT);
		s.setScrum((Scrum)DatabaseAccess.getInstance().getDataById(s.getScrum().getId(), DatabaseAccess.SCRUM));
		return s;
	}

	public ArrayList<Sprint> getSprintByScrum(int id) {
		ArrayList<Sprint> list = new ArrayList<Sprint>();
		for (AbstractModel d : DatabaseAccess.getInstance().getSprintByScrum(id)){
			list.add(getSprintById(((Sprint) d).getId()));
		}
		return list;
	}
}
